<%@page contentType="text/html; charset=utf-8"%>

<div class="form-container">
	<form id="form">
		<table class="tableform">
			<tr>
				<th>名称：</th>
				<td style="position: relative;">
					<input name="text" class="easyui-validatebox" type="text" data-options="required: true" style="float:left;"/>
					<div id="icheck" style="position: absolute;left:235px;top:2px;">
						<input id="input-2" type="checkbox" name="checked" value="true"> <label class="irl" for="input-2">默认显示</label>
					</div>
				</td>
			</tr>
			<tr>
				<th>图标：</th>
				<td>
					<input name="icon" class="easyui-validatebox" type="text" value="fa fa-clone" />
				</td>
			</tr>
			<tr>
				<th>颜色：</th>
				<td>
					<input name="color" class="easyui-validatebox" type="text" />
				</td>
			</tr>
			<tr>
				<th>样式：</th>
				<td>
					<div id="icheck">
						<input id="sex1" type="radio" name="mode" value="list" checked="checked">
						<label class="irl" for="mode1">大图标列表</label>　
						<input id="sex2" type="radio" name="mode" value="tree">
						<label class="irl" for="mode2">树状</label>
					</div>
				</td>
			</tr>
			<tr>
				<th>是否禁用：</th>
				<td>
					<div id="icheck">
						<input id="status1" type="radio" name="disabled" value="false" checked="checked">
						<label class="irl" for="disabled1">可用</label>　
						<input id="status2" type="radio" name="disabled" value="true">
						<label class="irl" for="disabled2">禁用</label>　
					</div>
				</td>
			</tr>
			<tr style="display:none">
				<td>
					<input type="hidden" name="id" value="${id}">
				</td>
			</tr>
		</table>
	</form>
</div>

<script>
	var form_url = "${ctx}/admin/sys/menu/add", id = "${id}" ;
	$(function(){
		$('#icheck input').iCheck({
			checkboxClass: 'icheckbox_minimal-blue',
			radioClass: 'iradio_square-blue'
	   	});
		
		if(undefined != id && "" != id) {
			form_url = "${ctx}/admin/sys/menu/update" ;
			$.ajax({
				type: "GET", dataType: "JSON",
				url: "${ctx}/admin/sys/menu/get/"+id,
				success: function(result) {
					$("input[name=disabled][value="+result.disabled+"]").iCheck('check') ;
					$("input[name=mode][value="+result.mode+"]").iCheck('check') ;
					$("input[name=checked][value="+result.checked+"]").iCheck('check') ;
					$("#form").form("load", result);
				},
				complete: function(XMLHttpRequest, textStatus){},
				error: function(){
					$.easyui.loaded();
					alert("请求出错处理") ;
				}
			});
		}
		
	});
	
	//提交表单数据
	var submitNow = function($d, $dg, flag) {
		$.post(form_url, $("#form").form("getData"), function(result) {
			if (result.status) {
				$dg.datagrid('reload');alertify.success(result.message);$.easyui.loaded();
				if(flag==undefined||flag==false){$d.dialog("close") ;}
			} else {
				$.easyui.loaded();$.messager.alert("错误", result.message, "error");
			}
		}, 'json').error(function() { $.easyui.loaded(); });
	};
	
	//验证表单
	var submitForm = function($d, $dg, flag) { 
		if($('#form').form('validate')) {
			$.easyui.loading({ msg: "数据提交中，请稍等..." });
			submitNow($d, $dg, flag) ;
		}
	};
</script>

